{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b171aeaa",
   "metadata": {},
   "source": [
    "## Cogniswitch LlamaPack\n",
    "\n",
    "**Use CogniSwitch to build production ready applications that can consume, organize and retrieve knowledge flawlessly. Using the framework of your choice, in this case LlamaIndex, CogniSwitch helps alleviate the stress of decision making when it comes to, choosing the right storage and retrieval formats. It also eradicates reliability issues and hallucinations when it comes to responses that are generated. Get started by interacting with your knowledge in a few simple steps**\n",
    "\n",
    "visit [https://www.cogniswitch.ai/developer](https://www.cogniswitch.ai/developer?utm_source=llamaindex&utm_medium=llamaindexbuild&utm_id=dev).\n",
    "\n",
    "**Registration:**\n",
    "- Signup with your email and verify your registration\n",
    "- You will get a mail with a platform token and OAuth token for using the services.\n",
    "\n",
    "\n",
    "**Step 1: Import the CogniSwitch Agent pack:**\n",
    "- Import the CogniSwitch agent pack from the llamapacks.   \n",
    "\n",
    "**Step 2: Instantiate the CogniswitchAgentPack:**\n",
    "- Instantiate the CogniSwitch agent pack with all the credentials. \n",
    "\n",
    "**Step 3: CogniSwitch Store data:**\n",
    "- Make the call to the agent by giving the file path or url to the agent input.\n",
    "- The agent will pick the tool and use the file/url and it will be processed and stored in your knowledge store.\n",
    "- You can check the status of document processing with a call to the agent. Alternatively you can also check in [cogniswitch console](https://console.cogniswitch.ai:8443/login?utm_source=llamaindex&utm_medium=llamaindexbuild&utm_id=dev). \n",
    "\n",
    "**Step 4: CogniSwitch Answer:**\n",
    "- Make the call to the agent by giving query as agent input.\n",
    "- You will get the answer from your knowledge as the response."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b47672f3",
   "metadata": {},
   "source": [
    "### Import the required libraries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "69453237",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_hub.llama_packs import CogniswitchAgentPack\n",
    "import os\n",
    "import warnings\n",
    "\n",
    "warnings.filterwarnings(\"ignore\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a768e9aa",
   "metadata": {},
   "source": [
    "### Cogniswitch Credentials and OpenAI token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7e46b7fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# os.environ[\"OPENAI_API_KEY\"] = <Your OpenAI API token>\n",
    "\n",
    "# cs_token = <Your Cogniswitch token>\n",
    "# oauth_token = <Your cogniswitch authentication token>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "76933442",
   "metadata": {},
   "outputs": [],
   "source": [
    "cogniswitch_tool_kwargs = {\"cs_token\": cs_token, \"apiKey\": oauth_token}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4a4d41b",
   "metadata": {},
   "source": [
    "### Instantiate the Cogniswitch Agent Pack"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7c1d0e87",
   "metadata": {},
   "outputs": [],
   "source": [
    "cogniswitch_agent_pack = CogniswitchAgentPack(cogniswitch_tool_kwargs)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "842eb14d",
   "metadata": {},
   "source": [
    "### Run the agent to upload a URL "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "aa88805b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The URL has been successfully uploaded and is currently being processed. You will receive an email notification once the processing is complete.\n"
     ]
    }
   ],
   "source": [
    "response = cogniswitch_agent_pack.run(\n",
    "    \"Upload the URL- https://cogniswitch.ai/developer\"\n",
    ")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4b188c4c",
   "metadata": {},
   "source": [
    "### Run the agent to get the status of the document"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5dbd8989",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The document with the URL \"https://cogniswitch.ai/developer\" is currently being processed.\n"
     ]
    }
   ],
   "source": [
    "response = cogniswitch_agent_pack.run(\n",
    "    \"tell me the status of the document https://cogniswitch.ai/developer\"\n",
    ")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "927313f8",
   "metadata": {},
   "source": [
    "### Run the agent to upload a file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c0f476e3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The file \"sample_file.txt\" has been successfully uploaded and is currently being processed. You will receive an email notification once the processing is complete.\n"
     ]
    }
   ],
   "source": [
    "response = cogniswitch_agent_pack.run(\"Upload this file- sample_file.txt\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "019c955c",
   "metadata": {},
   "source": [
    "### Run the agent to ask a question"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1da48417",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cogniswitch is a system that organizes and explores data intuitively. It streamlines research and integrates human expertise, while also fine-tuning knowledge.\n"
     ]
    }
   ],
   "source": [
    "response = cogniswitch_agent_pack.run(\"Tell me about cogniswitch\")\n",
    "print(response)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "llama_index_env",
   "language": "python",
   "name": "llama_index_env"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
